#include "WidgetXml.h"
#include "DefineCommon.h"
#include "EItem.h"
#include "EItemManager.h"
#include "qdom.h"
#include "qfiledialog.h"
#include "ui_WidgetXml.h"

#include <QMessageBox>
#include <QDomDocument>
#include <PluginXmlFunction.h>
#include <WidgetsManager.h>
#include <WidgetTree.h>

WidgetXml::WidgetXml(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::WidgetXml)
{
    ui->setupUi(this);
    

    ui->verticalLayout->removeItem(ui->horizontalLayout);
    


    QObject::connect(ui->actionTestXml,
                     SIGNAL(triggered(bool)),
                     this,
                     SLOT(slotActionTestXml(bool))
                     );
}

WidgetXml::~WidgetXml()
{
    delete ui;
}


QAction* WidgetXml::getAction(const QString& name)
{
	QAction* actionPtr = NULL;
    if (name == "actionOpenFile3dXml")
    {
    }
    else if (name == "actionTestXml")
    {
        actionPtr = ui->actionTestXml;
    }

	return actionPtr;
}


void WidgetXml::slotActionTestXml(bool value)
{
    //ELOG_DEBUG("testing xml");
    QString fileName = "../project/CAAComTest/CAAComTest/bin/Debug/cat_part_output.xml";
    /*QString fileName = QFileDialog::getOpenFileName(this, 
                                              "Read a xml file(.xml)", 
                                            ".", 
                                            "*.xml");*/
    if(fileName.isEmpty())
    {
        return;
    }

    EItemPtr itemRoot = PluginXmlFunction::convertXmlFileToEItem(fileName);
    EItemManager::instance()->getItemTreeRoot()->addChild(itemRoot);
    WidgetTree* wTree = (WidgetTree*)WidgetsManager::instance()->getWidgetFromMap("WidgetTree");
    wTree->slotButtonRefresh(true);
}
